<?php require('connections/con_gl.php'); ?>

<?php

cekAkses($_SESSION[akses],"PJ-4");

$currentPage = $_SERVER["PHP_SELF"];



$maxRows_data = 8;

$pageNum_data = 0;

if (isset($_GET['pageNum_data'])) {

  $pageNum_data = $_GET['pageNum_data'];

}

$startRow_data = $pageNum_data * $maxRows_data;

$cr_txt = str_replace("+"," ",$_REQUEST[cr_txt]);

mysql_select_db($database_con_gl, $con_gl);

$query_data = "SELECT gl_trans.no_ref, gl_trans.akun, gl_rtrans.tgl, gl_trans.transaksi, gl_trans.total, gl_rtrans.kontak, gl_rtrans.metodebyr, gl_kontak.nama, gl_trans.id FROM gl_trans, gl_rtrans, gl_kontak WHERE gl_rtrans.jenis=3 AND gl_rtrans.no_ref = gl_trans.no_ref AND gl_kontak.id = gl_rtrans.kontak AND gl_trans.pos='K' AND gl_trans.x_ref <>''";

if(!strstr($_SESSION[akses],'A-1-4')) {

	$query_data .= " AND gl_rtrans.gudang='$_SESSION[lokasi]'";

}

if($_GET[cr_txt]<>'' OR $_GET[cr_txt]<>'+') {

	$q = str_replace("+"," ",$_GET[cr_txt]);

	$query_data .=" AND (gl_trans.no_ref LIKE '%%$q%%' OR gl_trans.transaksi LIKE '%%$q%%' OR gl_kontak.nama LIKE '%%$q%%' OR gl_rtrans.tgl LIKE '%%$q%%')";

}

$query_data .=" GROUP BY gl_rtrans.no_ref desc";
$data = mysql_query($query_data, $con_gl) or die(mysql_error());
$totalRows_data = mysql_num_rows($data);
$totalPages_data = floor($totalRows_data / $maxRows_data);
$query_data .=" LIMIT $startRow_data, $maxRows_data";
$data = mysql_query($query_data, $con_gl) or die(mysql_error());
$totalRow_data = mysql_num_rows($data);
$row_data = mysql_fetch_assoc($data);



if (isset($_GET['totalRows_data'])) {

  $totalRows_data = $_GET['totalRows_data'];

} else {

  $all_data = mysql_query($query_data);

  $totalRows_data = mysql_num_rows($all_data);

}

$totalPages_data = ceil($totalRows_data/$maxRows_data)-1;



$queryString_data = "";

if (!empty($_SERVER['QUERY_STRING'])) {

  $params = explode("&", $_SERVER['QUERY_STRING']);

  $newParams = array();

  foreach ($params as $param) {

    if (stristr($param, "pageNum_data") == false && 

        stristr($param, "totalRows_data") == false) {

      array_push($newParams, $param);

    }

  }

  if (count($newParams) != 0) {

    $queryString_data = "&" . htmlentities(implode("&", $newParams));

  }

}

$queryString_data = sprintf("&totalRows_data=%d%s", $totalRows_data, $queryString_data);

include('include/widget_exportall.php');

?>

<h1>Pembayaran Piutang</h1>

<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable"> 

  <tr class="hide">

    <td><?php if(strstr($_SESSION[akses],"PJ-4-1")) { ?><a href="index.php?component=pembayaranpiutang&amp;task=add"><img src="images/add_new.png" border="0" /></a><?php } ?></td>

    <td>&nbsp;</td>

    <td colspan="5" align="right"><form id="search" name="search" method="post" action="">

      <label>

      <input name="cr_txt" type="text" id="cr_txt" value="<?php echo $_REQUEST['cr_txt'];?>" size="30" maxlength="100" />
      </label>

      <label>

      <input name="Search" type="submit" id="Search" value="Search" />
      </label>

    </form>

	<?php

	if(isset($_POST['Search'])) {

		echo "<script>window.location=\"index.php?component=pembayaranhutang&cr_txt=".str_replace(" ","+",$_POST[cr_txt])."\";</script>";

	}

	?></td>
  </tr>

  <tr>

    <th width="120"><strong>Tanggal</strong></th>

    <th width="146"><strong>No. Referensi</strong></th>

    <th width="276"><strong>Pelanggan</strong></th>

    <th width="300" align="left"><strong>Keterangan</strong></th>

    <th width="150">Metode Pembyrn </th>
    <th width="150"><strong>Total</strong></th>

    <th width="248" align="center" class="hide"><strong>Aksi</strong></th>
  </tr>

  <?php if($totalRows_data > 0) { ?>

  <?php do { ?>

  <?php

mysql_select_db($database_con_gl, $con_gl);

$query_hitung = "SELECT sum(gl_trans.total) as total FROM gl_trans WHERE gl_trans.no_ref='$row_data[no_ref]' AND pos='K'";

$hitung = mysql_query($query_hitung, $con_gl) or die(mysql_error());

$row_hitung = mysql_fetch_assoc($hitung);

$totalRows_hitung = mysql_num_rows($hitung);

  ?>

    <tr valign="top" bgcolor="#FFFFFF">

      <td align="left"><?php tanggal($row_data['tgl'],"tampilkan"); ?></td>

      <td align="left"><a href="include/jurnalvoucher.php?referensi=<?php echo $row_data['no_ref'];?>" onclick="NewWindow(this.href,'name','940','300','yes');return false" title="Jurnal Voucher"><?php echo $row_data['no_ref']; ?></a></td>

      <td><?php echo $row_data['nama']; ?></td>

      <td align="left"><?php echo $row_data['transaksi']; ?></td>

      <td align="left"><?php echo $row_data['metodebyr']; ?></td>
      <td align="right"><?php echo number_format($row_hitung[total],0,',','.').",-"; ?></td>

      <td align="center" bgcolor="#FFFFFF" class="hide"><?php if(strstr($_SESSION[akses],"PJ-4-2")) { ?><a href="index.php?component=pembayaranpiutang&amp;task=edit&amp;noreferensi=<?php echo $row_data['no_ref']; ?>&amp;supplier=<?php echo $row_data['kontak'];?>&amp;akun=<?php echo $row_data['akun']; ?>"><img src="images/edit_.png" border="0" /></a><?php } ?> <?php if(strstr($_SESSION[akses],"PJ-4-3")) { ?><a href="index.php?component=pembayaranpiutang&task=delete&noreferensi=<?php echo $row_data['no_ref']; ?>&amp;akun=<?php echo $row_data['akun']; ?>" class="ask"><img src="images/delete_.png" border="0" /></a><?php } ?></td>
    </tr>

    <?php } while ($row_data = mysql_fetch_assoc($data)); ?>
	<?php if($totalRows_data > $maxRows_data) { ?>
    <tr class="hide">
      <td colspan="11"><table border="0" align="left" width="50%">
          <tr>
            <td width="3%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, 0, $queryString_data); ?>"><img src="First.gif" border=0 ></a>
                <?php } // Show if not first page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, max(0, $pageNum_data - 1), $queryString_data); ?>"><img src="Previous.gif" border=0></a>
                <?php } // Show if not first page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, min($totalPages_data, $pageNum_data + 1), $queryString_data); ?>"><img src="Next.gif" border=0></a>
                <?php } // Show if not last page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, $totalPages_data, $queryString_data); ?>"><img src="Last.gif" border=0></a>
                <?php } // Show if not last page ?>            </td>
			<td width="88%">Halaman : <?php echo $pageNum_data+1; ?>, Ditampilkan <?php echo $totalRow_data; ?> dari <?php echo $totalRows_data; ?> total data</td>
          </tr>
        </table></td>
    </tr>
	<?php } ?>
   <?php }else{ ?>

  <tr bgcolor="#FFFFFF">

    <td colspan="7">Data tidak ada !!! </td>
  </tr>

  <?php } ?>

  <tr class="hide">

    <td colspan="7"><?php if(strstr($_SESSION[akses],"PJ-4-1")) { ?><a href="index.php?component=pembayaranpiutang&amp;task=add"><img src="images/add_new.png" border="0" /></a><?php } ?></td>
  </tr>
</table>
